/*
 *  Copright: 2008 Philipp Leitner, Distributed Systems Group,
 *            TU Wien, leitner@infosys.tuwien.ac.at
 *
 *  This file is part of DAIOS.
 *
 *  DAIOS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation.
 * 
 *  DAIOS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with DAIOS.  If not, see
 *  <http://www.gnu.org/licenses/>.
 * 
 */

package at.ac.tuwien.infosys.dsg.daios.wsdl.matcher;

import java.util.Hashtable;

import at.ac.tuwien.infosys.dsg.daios.framework.interfaces.IConstants;
import at.ac.tuwien.infosys.dsg.daios.wsdl.WSDLEncoding;

/**
 * This static class maps concrete Matcher instances (subclasses
 * of
 * <link>at.ac.tuwien.infosys.dsg.daios.wsdl.matcher.Matcher</link>
 * ) to Web Service invocation styles (document or rpc).
 * 
 * <p>
 * 
 * This mapper class should be used as a factory.
 * 
 * @author philipp
 *
 */
public class WSDLStyleMapper {
	
	// the mapping table
	private static Hashtable<WSDLEncoding,Matcher> mappings = null;
	
	// create the mappings on load
	static {
		
		mappings = new Hashtable<WSDLEncoding,Matcher>();
		mappings.put(new WSDLEncoding(IConstants.RPC_STYLE,
				IConstants.ENCODED_STYLE), new RPCMatcher());
		mappings.put(new WSDLEncoding(IConstants.DOC_STYLE,
				IConstants.WRAPPED_STYLE), new DocumentWrappedMatcher());
		mappings.put(new WSDLEncoding(IConstants.DOC_STYLE,
				IConstants.LITERAL_STYLE), new DocumentLiteralMatcher());		
		
	}
	
	/**
	 * Return the right matcher for an invocation style.
	 * 
	 * @param style The invocation style (document or rpc).
	 * Null if any other invocation style is being used.
	 * @return The matcher instance associated with the given
	 * invocation style.
	 */
	public static Matcher get(WSDLEncoding style) {
		return mappings.get(style);
	}
	
}
